<?


FUNCTION barstructure($pourc){

echo"
<table width=\"100\" height=\"11\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\" bgcolor=\"#CCCCCC\" background=\"../images/divers/bar01grille.gif\">
  <tr>
    <td><table width=\"$pourc\" height=\"11\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"../../images/divers/bar01.gif\">
        <tr><td></td></tr>
      </table></td>
  </tr>
</table>";
}

FUNCTION kill_unit($unit_tmp,$ter_tmp){

$unit_tmp3=EXPLODE("-",$ter_tmp);
       $unit_tmp=trim($unit_tmp);

        $i=0;
        FOREACH($unit_tmp3 as $unit_tmp2){
             $unit_tmp2=trim($unit_tmp2);
            IF ($unit_tmp2!=$unit_tmp){
               $unit_def[$i]=$unit_tmp2;

               $i++;
             }
        }
         //Remmettre les unit dans terrain[3]
         if ($i!=0){
             $ter_tmp=implode("-",$unit_def);
         }
         ELSE{

            $ter_tmp="0";
        }


        RETURN $ter_tmp;
}

FUNCTION kill_unit_real($unit_tmp2){
$query="SELECT unite_loc,unite_sloc,unite_nombre,unite_unit_id FROM SDunite where unite_id=$unit_tmp2";
$resultat2=mysql_query($query);
$tmp3=mysql_fetch_row($resultat2);

$ter_tmp=terid($tmp3[0]);
$terrain=EXPLODE("/",$ter_tmp);

$terrain[3]=kill_unit($unit_tmp2,$terrain[3]);

//Remttre l'enregistrement de ter dans la bonne variable.
$tmp2=implode("/",$terrain);
          

update_ter($tmp3[0],$tmp2);

$query="DELETE FROM SDunite WHERE unite_id=$unit_tmp2";
$resultat2=mysql_query($query);
                           
}


FUNCTION TEST_RESS($RESSOURCE){

$tmp_ress= EXPLODE("/",$RESSOURCE);

$nbr_ress=NULL;
FOREACH( $tmp_ress as $ress){
          $ress2=EXPLODE("-",$ress);
          $nbr_ress+=$ress2[1];
}//Fin du foreach

 RETURN $nbr_ress;
}

 FUNCTION ADD_RESS($ress_a_val,$ress_donnee){

$ressource_tmp=EXPLODE("/",$ress_a_val);
$nbr_ress=count($ressource_tmp);
$stock_tmp=EXPLODE("/",$ress_donnee);
$nbr_stock=count($stock_tmp);

FOR ($i=0;$i<$nbr_ress;$i++){  //FOR #01

$ressource=EXPLODE("-",$ressource_tmp[$i]);
$ok=0;

     FOR ($i2=0;$i2<$nbr_stock;$i2++){  //FOR #02
              $stock=EXPLODE("-",$stock_tmp[$i2]);
             //TEST POUR savoir si la ressourse est bien la bonne.
             //---------------------------------------------------

             //echo"-$ressource[0]/$stock[0]<BR>";
             IF ($ressource[0]==$stock[0]){
                $stock[1]+=$ressource[1];
                $stock_tmp[$i2]=IMPLODE("-",$stock);
                $ok=1; BREAK;


             }




     }                         //Fin du for #02
//TEST pour savoir si il a trouver qq chose
//-----------------------------------------
IF ($ok==0){  //IF du ok.
IF($nbr_stock>1){  //Si il y a plus qu'un enregistrement  IF#01
    $stock_tmp[$nbr_stock]=$ressource_tmp[$i];
    $nbr_stock++;

}//FIN di if #01
//Si il n'y a rien en stock.
ELSE{
  $stock_tmp[0]=$ressource_tmp[$i];
  $nbr_stock++;

}//Fin du else
}//Fin du if du ok


}
$stock_record=IMPLODE("/",$stock_tmp);
RETURN $stock_record;
}//Fin de la fonction

FUNCTION envoi_mess_ville($destinataire,$txt,$titre,$sorte){

$query="INSERT INTO sdm_ville (message_date,message_sujet,message_texte,message_sloc,message_loc,message_sorte) VALUES (NOW(),'$titre','$txt','v',$destinataire,$sorte)";
$resultat2=mysql_query($query);
}



?>
